import { useRef } from 'react'
import Child from '../components/child';
function Home() {
    // 获取h3节点   创建ref对象 相当于class 中的 createRef
    let h3ref = useRef()
    console.log(h3ref);
    let childref = useRef();
    return (
        <div>
            <h3 ref={h3ref}>useRef- hooks的使用</h3>
            <button onClick={() => {
                console.log(h3ref.current);
                h3ref.current.style.color = 'red'
            }}>获取h3标签</button>
            {/* ref不能直接获取函数式组件实例*/}
            <Child ref={childref}></Child>
            <button onClick={()=>{
                console.log(childref);
            }}>获取child实例</button>
        </div>
    )
}


export default Home